package copyengine.ui
{
    import copyengine.ui.component.button.CEButton;
    import copyengine.ui.component.button.CESelectableButton;
    import copyengine.ui.component.button.animation.CEColorFilterButtonAnimation;
    import copyengine.ui.component.button.animation.CEColorFilterSelectableButtonAnimation;
    import copyengine.ui.component.progress.CEProgressBar;
    import copyengine.ui.component.progress.animation.CEChangeSizeProgressBarAnimation;
    import copyengine.ui.component.progress.animation.CEMaskProgressBarAnimation;
    import copyengine.ui.component.tabbar.CETabbar;
    import copyengine.ui.display.movieClip.CEMovieClip;

    import starling.display.DisplayObject;
    import starling.display.DisplayObjectContainer;

    public class CEGuiUtils
    {
        public function CEGuiUtils()
        {
        }

        //=====================
        //== Button
        //=====================

        public static function getColorFilterButton(_mc:DisplayObject, _onClickCallback:Function = null):CEButton
        {
            var button:CEButton = new CEButton(_mc);
            button.onClickCallBack = _onClickCallback;

            var animation:CEColorFilterButtonAnimation = new CEColorFilterButtonAnimation();
            animation.initialize(_mc);
            button.animation = animation;

            return button;
        }

        public static function getColorFilterSelectableButton(_mc:DisplayObject, _onClickCallback:Function = null, _isClickToSelected:Boolean = true):CESelectableButton
        {
            var button:CESelectableButton = new CESelectableButton(_mc);
            button.onClickCallBack = _onClickCallback;

            var animation:CEColorFilterSelectableButtonAnimation = new CEColorFilterSelectableButtonAnimation();
            animation.initialize(_mc);
            button.animation = animation;
            button.isClickToSelect = _isClickToSelected;

            return button;
        }

        //=====================
        //== Tabbar
        //=====================

        public static function getColorFilterTabbar(_mc:DisplayObjectContainer, _defaultTab:String, _onTabChangeCallback:Function = null):CETabbar
        {
            var subButtonsVector:Vector.<CESelectableButton> = new Vector.<CESelectableButton>();
            var totalChildNum:int = _mc.numChildren;
            for (var childIndex:int = 0; childIndex < totalChildNum; childIndex++) {
                var subChild:DisplayObject = _mc.getChildAt(childIndex);
                if (subChild is CEMovieClip) {
                    var subBtn:CESelectableButton = getColorFilterSelectableButton(subChild);
                    subButtonsVector.push(subBtn);
                }
            }
            var tabbar:CETabbar = new CETabbar(_mc, subButtonsVector, _defaultTab);
            tabbar.onTabChangeCallback = _onTabChangeCallback;
            return tabbar;
        }

        //=====================
        //== Progress
        //=====================

        public static function getMaskProgressBar(_mc:DisplayObject, _dir:int, _defaultPercent:Number = 100):CEProgressBar
        {
            var progressBar:CEProgressBar = new CEProgressBar(_mc);
            var animation:CEMaskProgressBarAnimation = new CEMaskProgressBarAnimation();
            animation.initialize(_mc, _dir);
            progressBar.animation = animation;
            progressBar.percent = _defaultPercent;
            return progressBar;
        }

        public static function getChangeSizeProgressBar(_mc:DisplayObject, _dir:int, _defaultPercent:Number = 100):CEProgressBar
        {
            var progressBar:CEProgressBar = new CEProgressBar(_mc);
            var animation:CEChangeSizeProgressBarAnimation = new CEChangeSizeProgressBarAnimation();
            animation.initialize(_mc, _dir);
            progressBar.animation = animation;
            progressBar.percent = _defaultPercent;
            return progressBar;
        }

    }
}
